<template>
	<view class="order-detail order-confirm">
		<view class='content'>
			<view class='price-detail'>
				<view class='p-header'>选购信息</view>
				<view class='p-list'>
					<view class='left'>车系</view>
					<view class='right'>
						<div class="span"><text style="font-weight: 600;">{{carConfig.seriesName}}</text></div>
					</view>
				</view>
				<view class='p-list'>
					<view class='left'>车型 </view>
					<view class='right'><text style="font-weight: 600;">{{carConfig.modelName || ''}}</text></view>
				</view>
				<view class='p-list'>
					<view class='left'>配置 </view>
					<view class='right'>{{carConfig.modelConfigureName}}
						<view class='money-color' style="padding-left: 5px;"> + ￥ {{carConfig.modelConfigureMoney}}
						</view>
					</view>
				</view>
				<view class='p-list'>
					<view class='left'>颜色 </view>
					<view class='right'>{{carConfig.colorName}}
						<view class='money-color' style="padding-left: 5px;"> + ￥ {{carConfig.colorMoney}}</view>
					</view>
				</view>

				<view class='p-list have-item'>
					<view class='left'>选装包</view>
					<view v-if="!(carConfig.servicepkgInfos && carConfig.servicepkgInfos.length)" class='right'><text
							style="padding-right: 5px;">无</text> + ￥ 0</view>
					<view v-else class='right'>
						<view style='font-weight: 400;display: inline-block;padding-right: 5px;'>
							{{carConfig.servicepkgInfos[0].serverName}}
						</view>
						+ ￥ {{carConfig.servicepkgInfos[0].serverMoney}}
					</view>
				</view>
				<view v-if="(carConfig.servicepkgInfos && carConfig.servicepkgInfos.length)" class="items-sub">
					{{carConfig.servicepkgInfos[0].uniqueContent}}
				</view>
				<!-- <view class='p-list have-item items' v-for="item in details.carConfig.servicepkgInfos" :key="item.id">
					<view class='right'>{{item.serverName}}</view> 
					<view class='right'>￥{{item.serverMoney}}</view>
				</view> -->
				<view class='p-list have-item'>
					<view class='left'>个性化</view>
					<view v-if="!(carConfig.uniqueserverInfos && carConfig.uniqueserverInfos.length)" class='right'>
						<view style="font-weight: 400;display: inline-block;padding-right: 5px;">无</view><text
							style="font-weight: 400;">+ ￥ 0</text>
					</view>
					<view v-else class='right'>
						<view style='font-weight: 400;display: inline-block;padding-right: 5px;'>
							{{carConfig.uniqueserverInfos[0].serverName}}
						</view>
						<text style="font-weight: 400;">+ ￥ {{carConfig.uniqueserverInfos[0].serverMoney}}</text>
					</view>
				</view>
				<view v-if="(carConfig.uniqueserverInfos && carConfig.uniqueserverInfos.length)" class="items-sub">
					{{carConfig.uniqueserverInfos[0].uniqueContent}}
				</view>
				<!-- <view class='p-list have-item items' v-for="item in details.carConfig.uniqueserverInfos" :key="item.id">
					{{item.uniqueContent}}
				</view> -->


				<!-- <view class='p-list have-item'>
					<view class='left'>选装包</view>
					<view class='right'>
						<view v-if="!(carConfig.servicepkgInfos && carConfig.servicepkgInfos.length)"
							style="display: inline-block;">无 <text style="font-weight: 600;">+ ￥ 0</text></view>
						<view v-else class='money-color'>+ ￥{{carConfig.servicepkgInfos[0].serverMoney}}</view>
					</view>
				</view>
				<view class='p-list have-item items' v-for="item in carConfig.servicepkgInfos" :key="item.id">
					<view class='left'>{{item.serverName}}</view>
				</view>
				<view class='p-list have-item'>
					<view class='left'>个性化</view>
					<view class='right'>
						<view v-if="!(carConfig.uniqueserverInfos && carConfig.uniqueserverInfos.length)"
							style="display: inline-block;">无 <text style="font-weight: 600;">+ ￥ 0</text></view>
						<view v-else class='money-color'> + ￥{{carConfig.uniqueserverInfos[0].serverMoney}}</view>
					</view>
				</view>
				<view class='p-list have-item items' v-for="item in carConfig.uniqueserverInfos" :key="item.id">
					<view class='left'>{{item.serverName}}:<text class="space">{{item.uniqueContent}}</text></view>
				</view> -->


				<!-- 六期加优惠券 -->
				<view class='p-list' @click="toMyCardListForUsed">
					<view class='left'>优惠券 </view>
					<view class="p-list"
						v-if="details.couponName!=''&&details.couponName!=null&&details.couponName!= undefined">
						<view class="orangeText" style="color: #3D3A3A;width: 200px;justify-content: flex-end; ">
							{{details.couponName}}</view>
						<u-icon name="arrow-up" style='margin-right: -8rpx;margin-left: 10rpx;'></u-icon>
					</view>
					<view class="p-list" v-else-if="availableCouponistNum>0">
						<view class="orangeText">{{availableCouponistNum}} 张可用</view>
						<u-icon name="arrow-up" style='margin-right: -8rpx;margin-left: 10rpx;'></u-icon>
					</view>
					<view class="p-list" v-else>
						<view class="orangeText" style="color: #ADB0AE;">暂无可用</view>
					</view>
				</view>
				<view class='p-list'>
					<view class='left'>优惠金额 </view>
					<view class='right'>
						<view class='money-color' style="padding-left: 5px;" v-if="showPreferential==true">
							￥{{Number(Number(carConfig.orderAmount||0) * 10000 - Number(carConfig.afterDiscountOrderAmount||0)* 10000) / 10000}}
						</view>
						<view class='money-color' style="padding-left: 5px;" v-else>
							￥0
						</view>
					</view>
				</view>


				<!-- 六期加优惠券 -->

				<view class='p-list total'>
					<view class='left weight'>总价</view>
					<view class='right' v-if="showPreferential==false">￥{{carConfig.orderAmount}}</view>
					<view class='right' v-else>￥{{carConfig.afterDiscountOrderAmount}}</view>
				</view>
			</view>

			<!-- =======================新增 金融信息 ===========================-->
			<view class='price-detail'>
				<view class='p-header'>金融信息</view>
				<view class='p-list'>
					<view class='left'>购车方式</view>
					<view class='right'>
						<div class="span" v-if="details.paymentType=='1'">金融分期</div>
						<div class="span" v-else>全款支付</div>
					</view>
				</view>
			</view>
			<!-- ========================新增 金融信息 ======================-->



		</view>

		<u--form labelPosition="left" :model="formData" :rules="rules" ref="uForm">
			<view class="form-title">收货信息</view>
			<u-form-item label="姓名" labelWidth='auto' prop="buyName" ref="buyName">
				<u-input v-model="formData.buyName" border="none" inputAlign='right' placeholder="请输入姓名"></u-input>
			</u-form-item>
			<u-form-item label="电话" labelWidth='auto' prop="buyPhone" ref="buyPhone">
				<u--input v-model="formData.buyPhone" border="none" inputAlign='right' placeholder="请输入电话" type='tel'>
				</u--input>
			</u-form-item>
			<u-form-item label="身份证号" labelWidth='auto' prop="buyCard" ref="buyCard">
				<u--input v-model="formData.buyCard" border="none" inputAlign='right' placeholder="请输入身份证号"
					type='idcard'></u--input>
			</u-form-item>

			<u-form-item label="城市" labelWidth='auto' prop="city" ref="city" v-if="details.paymentType=='1'">
				<u--input v-model="formData.cityName" border="none" inputAlign='right' :disabled='true'
					disabledColor='rgba(0,0,0,0)' color="#ADB0AE" placeholder="请选择城市"></u--input>
			</u-form-item>
			<u-form-item label="城市" labelWidth='auto' prop="city" ref="city" v-else @click="showCity = true">
				<u--input v-model="formData.cityName" border="none" inputAlign='right' :disabled='true'
					disabledColor='rgba(0,0,0,0)' placeholder="请选择城市"></u--input>
				<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>

			<block v-if="storeColumns[0] && storeColumns[0].length">
				<u-form-item label="门店" labelWidth='auto' prop="storeId" ref="storeId" v-if="details.paymentType=='1'">
					<u--input v-model="formData.storeName" border="none" inputAlign='right' :disabled='true'
						disabledColor='rgba(0,0,0,0)' color="#ADB0AE" placeholder="请选择门店"></u--input>
				</u-form-item>
				<u-form-item label="门店" labelWidth='auto' prop="storeId" ref="storeId" @click="showStore = true" v-else>
					<u--input v-model="formData.storeName" border="none" inputAlign='right' :disabled='true'
						disabledColor='rgba(0,0,0,0)' placeholder="请选择门店"></u--input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>
			</block>

			<u-form-item label="收货地址" labelWidth='auto' prop="buyAddress" ref="buyAddress">
				<u--textarea v-model="formData.buyAddress" autoHeight border='none' confirmType='done'
					placeholder="请输入收货地址"></u--textarea>
			</u-form-item>
			<u-form-item label="期望收货方式" labelWidth='auto' prop="deliveryType" ref="deliveryType">
				<u-radio-group v-model="formData.deliveryType+''" placement="row" @change="deliveryTypeGroupChange">
					<u-radio activeColor="#EA5404" name='2' label="送货上门"></u-radio>
					<u-radio activeColor="#EA5404" name='1' label="门店自提"></u-radio>
				</u-radio-group>
			</u-form-item>
			<view class="tips">提醒：送货上门服务为增值商品选项，交付门店会致电协商付费。</view>

			<view class="form-title">发票信息</view>

			<!-- =======================新增 发票类型 ===========================-->
			<u-form-item class='lala' label="发票类型" labelWidth='auto' prop="invoiceType" ref="invoiceType">
				<u-radio-group v-model="formData.invoiceType+''" placement="column" @change="invoiceTypeGroupChange">
					<u-radio activeColor="#EA5404" name='1' label="机动车销售统一发票" :disabled="details.paymentType=='1'">
					</u-radio>
					<u-radio class="last-radip" activeColor="#EA5404" name='2' label="增值税专用发票"></u-radio>
				</u-radio-group>
			</u-form-item>
			<!-- =======================新增 发票类型 ===========================-->


			<u-form-item label="开票主体" labelWidth='auto' prop="isPersonal" ref="isPersonal">
				<u-radio-group v-model="formData.isPersonal+''" placement="row" @change="groupChange">
					<u-radio activeColor="#EA5404" name='1' label="个人"
						:disabled="formData.invoiceType=='2'||details.paymentType=='1'"></u-radio>
					<u-radio activeColor="#EA5404" name='2' label="企业"></u-radio>
				</u-radio-group>
			</u-form-item>

			<block v-if='formData.isPersonal == "1"'>
				<u-form-item label="姓名" labelWidth='auto' prop="buyNameFP" ref="buyNameFP">
					<u--input v-model="formData.buyNameFP" border="none" inputAlign='right' placeholder="请输入姓名">
					</u--input>
				</u-form-item>
				<u-form-item label="身份证号" labelWidth='auto' prop="buyCardFP" ref="buyCardFP">
					<u--input v-model="formData.buyCardFP" border="none" inputAlign='right' placeholder="请输入身份证号"
						type='idcard'>
					</u--input>
				</u-form-item>
			</block>

			<block v-else-if="formData.invoiceType=='1'&&formData.isPersonal == '2'">
				<u-form-item label="企业名称" labelWidth='auto' prop="buyBusiness" ref="buyBusiness">
					<u--input v-model="formData.buyBusiness" border="none" inputAlign='right' placeholder="请输入企业名称">
					</u--input>
				</u-form-item>
				<u-form-item label="社会统一识别码" labelWidth='auto' prop="buyCode" ref="buyCode">
					<u--input v-model="formData.buyCode" border="none" inputAlign='right' placeholder="请输入社会统一识别码">
					</u--input>
				</u-form-item>
			</block>


			<block v-else-if="formData.invoiceType=='2'&&formData.isPersonal =='2'">
				<u-form-item label="公司名称" labelWidth='auto' prop="corporateName" ref="corporateName">
					<u--input v-model="formData.corporateName" border="none" inputAlign='right' placeholder="请输入公司名称">
					</u--input>
				</u-form-item>
				<u-form-item label="单位税号" labelWidth='auto' prop="unitTaxNo" ref="unitTaxNo">
					<u--input v-model="formData.unitTaxNo" border="none" inputAlign='right' placeholder="请输入单位税号">
					</u--input>
				</u-form-item>
				<u-form-item label="注册地址" labelWidth='auto' prop="registeredAddress" ref="registeredAddress">
					<u--input v-model="formData.registeredAddress" border="none" inputAlign='right'
						placeholder="请输入注册地址">
					</u--input>
				</u-form-item>
				<u-form-item label="注册电话" labelWidth='auto' prop="registrationPhone" ref="registrationPhone">
					<u--input v-model="formData.registrationPhone" border="none" inputAlign='right'
						placeholder="请输入注册电话" type='tel'>
					</u--input>
				</u-form-item>
				<u-form-item label="开户银行" labelWidth='auto' prop="depositBank" ref="depositBank">
					<u--input v-model="formData.depositBank" border="none" inputAlign='right' placeholder="请输入开户银行">
					</u--input>
				</u-form-item>
				<u-form-item label="银行账号" labelWidth='auto' prop="bankAccount" ref="bankAccount">
					<u--input v-model="formData.bankAccount" border="none" inputAlign='right' placeholder="请输入银行账号"
						type='number'>
					</u--input>
				</u-form-item>
			</block>
			<view class="tips">提醒：增值税专用发票不可用于车辆上牌，谨慎选择。请认真核对开票信息，发票一经申请不可修改</view>

			<view class="form-title">支付信息</view>
			<view class='form-list'>
				<view class='left'>定金金额</view>
				<view class='right'>
					<view class="color">已支付</view> ￥{{details.depositAmount}}
				</view>
			</view>
			<view class='form-list'>
				<view class='left'>尾款</view>
				<!-- <view class='right' >￥{{(Number(details.orderAmount) * 100 - Number(details.depositAmount)* 100) / 100}}</view>
				 -->
				<view class='right' v-if="showPreferential==false">￥{{details.finalPayment}}</view>
				<view class='right' v-else>
					￥{{Number(Number(carConfig.afterDiscountOrderAmount||0) * 10000 - Number(details.depositAmount||0)* 10000) / 10000}}
				</view>

			</view>

		</u--form>

		<u-picker :show="showCity" :columns="cityColumns" keyName="label" confirmColor='#EA5404' @cancel='cancel'
			@confirm="cityConfirm" @change="changeCityHandler"></u-picker>
		<u-picker :show="showStore" :columns="storeColumns" keyName="storeName" confirmColor='#EA5404' @cancel='cancel'
			@confirm="storeConfirm" @change="changeStoreHandler"></u-picker>
		<u-modal :show="showConfirm" title='确认信息' :content='content' confirmText='确定' confirmColor='#EA5404'
			:showCancelButton='true' cancelColor='#3D3A3A' @confirm="confirm" @cancel="cancle"></u-modal>

		<view class="agreement" @click="popupShow = true">点击查看《购车协议》</view>
		<purchaseAgreementPop :popupShow="popupShow" :notTimer="true" @closePop="closePop" ref="countDown">
		</purchaseAgreementPop>
		<view class='o-footer'>
			<view class='f-btn color' @click='submit'>支付尾款</view>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	const util = require('@utils/util.js');
	const network = require('@manager/network-manager.js');
	const dialog = require('@utils/dialog.js');
	import Validator from '@manager/validator.js'
	import purchaseAgreementPop from '@components/purchase-agreement-pop/purchase-agreement-pop.vue';
	export default {
		components: {
			purchaseAgreementPop
		},
		data() {
			return {
				status: 5,
				id: null,
				details: {},
				carConfig: {},
				show: false,
				dialogContent: '您确认要取消订单吗?',
				title: '取消订单',
				confirmText: '确认',
				popupShow: false,
				modelIdToCoupon: '',
				statusList: [{
						text: '定金待支付',
						value: 1
					},
					{
						text: '订单审批中',
						value: 2
					}, // 定金已支付
					{
						text: '订单已审批',
						value: 3
					},
					{
						text: '计划生产',
						value: 4
					},
					{
						text: '生产中',
						value: 5
					},
					{
						text: '已入库',
						value: 6
					},
					{
						text: '已入库',
						value: 7
					},
					{
						text: '已发货',
						value: 8
					},
					{
						text: '已到店',
						value: 9
					},
					{
						text: '待评价',
						value: 10
					},
					{
						text: '待评价',
						value: 11
					},
					{
						text: '已完成',
						value: 12
					},
					{
						text: '订单已取消',
						value: 13
					},
					{
						text: '订单关闭',
						value: 14
					},
					// {text: '退款成功', value: '15'},
					// {text: '不予退款', value: '16'},
				],
				formData: {
					buyName: null, // 姓名
					buyPhone: null, // 电话
					buyCard: null, // 身份证号
					province: null, // 省
					city: null, // 市
					cityName: null, // 市
					storeId: null, // 门店
					storeName: null, // 门店
					buyAddress: null, // 收货地址
					deliveryType: null, // 期望收货方式
					invoiceType: null, //发票类型
					isPersonal: null, // 开票主体
					buyNameFP: null, // 开票姓名
					buyCardFP: null, // 开票身份证号
					buyBusiness: null, // 企业名称
					buyCode: null, // 社会统一识别码
					//新增值税发票六字段------------
					corporateName: null, // 公司名称
					unitTaxNo: null, // 单位税号
					registeredAddress: null, // 注册地址
					registrationPhone: null, // 注册电话
					depositBank: null, //开户银行
					bankAccount: null, //银行账号
					//新增值税发票六字段------------
					paymentFlag: null, // 支付方式
					paymentType: null, //金融方式
					couponNo: null, //优惠券id

				},
				myAvailableCouponData: {},
				availableCouponistNum: 0,
				refreshDetail: true,
				rules: {
					buyName: [{
							required: true,
							message: '姓名不能为空',
							trigger: ['blur', 'change']
						},
						{
							min: 1,
							max: 20,
							message: '姓名过长'
						}
					],
					buyPhone: [{
							required: true,
							message: '电话不能为空',
							trigger: ['blur', 'change']
						},
						{
							validator: (rule, value, callback) => {
								return Validator.isMobile(value)
							},
							message: '请输入正确格式的手机号'
						}
					],
					buyCard: [{
							required: true,
							message: '身份证号不能为空',
							trigger: ['blur', 'change']
						},
						{
							validator: (rule, value, callback) => {
								return Validator.isIDCardFormat(value)
							},
							message: '请输入正确格式的身份证号'
						}
					],
					city: [{
						required: true,
						message: '城市不能为空',
						trigger: ['blur', 'change']
					}],

					buyAddress: [{
						required: true,
						message: '收货地址不能为空',
						trigger: ['blur', 'change']
					}],
					deliveryType: [{
							required: true,
							message: '期望收货方式不能为空',
							trigger: ['blur', 'change']
						},
						{
							validator: (rule, value, callback) => {
								return (value == '' || value == 'null') ? false : true
							},
							message: '期望收货方式不能为空'
						}
					],
					invoiceType: [{
							required: true,
							message: '发票类型不能为空',
							trigger: ['blur', 'change']
						},
						{
							validator: (rule, value, callback) => {
								return (value == '' || value == 'null') ? false : true
							},
							message: '发票类型不能为空'
						}
					],
					isPersonal: [{
							required: true,
							message: '开票主体不能为空',
							trigger: ['blur', 'change']
						},
						{
							validator: (rule, value, callback) => {
								return (value == '' || value == 'null') ? false : true
							},
							message: '开票主体不能为空'
						}
					],
					buyNameFP: [{
							required: true,
							message: '开票姓名不能为空',
							trigger: ['blur', 'change']
						},
						{
							min: 1,
							max: 20,
							message: '姓名过长'
						}
					],
					buyCardFP: [{
							required: true,
							message: '开票身份证号不能为空',
							trigger: ['blur', 'change']
						},
						{
							validator: (rule, value, callback) => {
								return Validator.isIDCardFormat(value)
							},
							message: '请输入正确格式的身份证号'
						}
					],
					buyBusiness: [{
							required: true,
							message: '企业名称不能为空',
							trigger: ['blur', 'change']
						},
						{
							min: 1,
							max: 100,
							message: '企业名称过长'
						}
					],
					buyCode: [{
							required: true,
							message: '社会统一识别码不能为空',
							trigger: ['blur', 'change']
						},
						{
							validator: (rule, value, callback) => {
								return (value.length == 15) || (value.length === 18)
							},
							message: '请输入正确格式的社会统一识别码'
						}
					],

					corporateName: [{
							required: true,
							message: '公司名称不能为空',
							trigger: ['blur', 'change']
						},
						{
							min: 1,
							max: 100,
							message: '公司名称过长'
						}
					],

					unitTaxNo: [{
							required: true,
							message: '单位税号不能为空',
							trigger: ['blur', 'change']
						},
						{
							validator: (rule, value, callback) => {
								return (value.length == 15) || (value.length === 18)
							},
							message: '请输入正确格式的单位税号'
						}
					],
					bankAccount: [{
							required: true,
							message: '银行账号不能为空',
							trigger: ['blur', 'change']
						},
						{
							validator: (rule, value, callback) => {
								return Validator.verifyBankCard(value)
							},
							message: '请输入正确格式的银行账号'
						}
					],
					paymentFlag: [{
						required: true,
						message: '支付方式不能为空',
						trigger: ['blur', 'change']
					}],


				},
				showCity: false,
				showStore: false,
				showConfirm: false,
				content: '信息提交后无法修改，请您确认所有信息准确无误',
				cityColumns: [
					[],
					[]
				],
				storeColumns: [],
				showPreferential: false
			}
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			if (options.id) this.id = String(options.id)
		},
		onShow: function() {
			this.showPreferential = false
			if (uni.getStorageSync('couponChoose')) {
				this.refreshDetail = false
				this.formData.couponNo = uni.getStorageSync('couponChoose').couponNo
				this.details.couponName = uni.getStorageSync('couponChoose').couponName
				uni.setStorageSync('couponChoose', null)
				this.getAmount(this.formData.couponNo)
			}
			if (this.refreshDetail == true) {
				this.getDetail()
				this.getProvinces()
			} else {
				this.refreshDetail = true
			}
		},
		methods: {
			//优惠券使用
			// couponChoose: function(couponNo, couponName) {
			// 	this.refreshDetail = false
			// 	this.formData.couponNo = couponNo
			// 	this.details.couponName = couponName
			// 	this.getAmount(couponNo)
			// },
			//尾款金钱计算带优惠券
			getAmount: function(couponNo) {
				var that = this;
				var uri = app.globalData.config.interfaces.URL_PRODUCT_LEVCCARORDERLIFAN_GETAMOUNT; //刷新页面配置
				var params = {
					"couponNo": couponNo,
					"orderId": this.details.orderId,
				};
				network.get(uri, params, 'json').then(res => {
					if (res.code == 200) {
						that.showPreferential = true
						that.carConfig.afterDiscountOrderAmount = res.data
					} else {
						uni.showToast({
							title: res.message,
							duration: 3000,
							icon: 'none'
						})
					}
				}).catch(res => {
					uni.showToast({
						title: res.errMsg,
						duration: 3000,
						icon: 'none'
					})
				});
			},


			//用户查询我的卡券 查询可用券数量
			getMyAvailableCoupon: function(modelId) {
				var that = this;
				var uri = app.globalData.config.interfaces.URL_ACTIVITY_CARD_GETMYAVAILABLECOUPON; //刷新页面配置
				var params = {
					"useScope": '购车',
					"carModelId": modelId,
					"carOrderPrice": that.details.orderAmount,
					"userId": app.globalData.userInfo.id
				};
				network.get(uri, params, 'json').then(res => {
					if (res.code == 200) {
						that.myAvailableCouponData = res.data
						that.availableCouponistNum = res.data.availableCouponistNum
					} else {
						uni.showToast({
							title: res.message,
							duration: 3000,
							icon: 'none'
						})
					}
				}).catch(res => {
					uni.showToast({
						title: res.errMsg,
						duration: 3000,
						icon: 'none'
					})
				});
			},
			//跳转选择优惠券
			toMyCardListForUsed: function() {
				if (this.availableCouponistNum > 0) {
					uni.navigateTo({
						url: '/module_my/pages/myCardList/myCardListForUsed?myAvailableCouponJson=' + JSON
							.stringify(this.myAvailableCouponData)
					});
				}

			},

			groupChange(n) {
				this.formData.isPersonal = n
				this.$refs.uForm.clearValidate()
				//如果选择个人，清空企业信息
				if (this.formData.isPersonal == 1) {
					//清空关于机动车销售统一发票的企业信息
					this.formData.buyBusiness = ''
					this.formData.buyCode = ''
					//清空关于增值税专用发票的企业信息
					this.formData.corporateName = ''
					this.formData.unitTaxNo = ''
					this.formData.registeredAddress = ''
					this.formData.registrationPhone = ''
					this.formData.depositBank = ''
					this.formData.bankAccount = ''
				}
				//如果选择企业，清空个人信息
				if (this.formData.isPersonal == 2) {
					this.formData.buyNameFP = ''
					this.formData.buyCardFP = ''
				}
			},
			deliveryTypeGroupChange(n) {
				this.formData.deliveryType = n
			},
			invoiceTypeGroupChange(n) {
				this.formData.invoiceType = n
				this.$refs.uForm.clearValidate()
				//清空开票主体 及以下所有需要选择的字段
				//清空开票主体
				this.formData.isPersonal = ''
				//清空个人信息
				this.formData.buyNameFP = ''
				this.formData.buyCardFP = ''
				//清空关于机动车销售统一发票的企业信息
				this.formData.buyBusiness = ''
				this.formData.buyCode = ''
				//清空关于增值税专用发票的企业信息
				this.formData.corporateName = ''
				this.formData.unitTaxNo = ''
				this.formData.registeredAddress = ''
				this.formData.registrationPhone = ''
				this.formData.depositBank = ''
				this.formData.bankAccount = ''
			},
			getStatusText(value) {
				let text = null
				this.statusList.forEach(item => {
					if (item.value == value) {
						text = item.text
					}
				})
				return text
			},
			getDetail() {
				var that = this
				let url = app.globalData.config.interfaces.URL_GET_CARORDER_ORDER
				let params = {
					"id": this.id
				};
				network.get(url, params, 'form').then(res => {
					if (res.code == 200) {
						this.details = res.data
						if (this.details.beforeAmount != undefined && this.details.beforeAmount != null && this
							.details.beforeAmount != '') {
							this.details.orderAmount = this.details.beforeAmount
						}
						this.details.finalPayment = (Number(this.details.orderAmount) * 100 - Number(this.details
							.depositAmount) * 100) / 100
						this.carConfig = res.data.carConfig ? res.data.carConfig : {}
						if (res.data.city) this.getStoreList(res.data.city)
						Object.keys(that.details).forEach((key) => {
							if (that.formData.hasOwnProperty(key)) {
								that.formData[key] = that.details[key]
							}
						})
						this.formData.deliveryType = this.formData.deliveryType + ''
						this.formData.invoiceType = this.formData.invoiceType + ''
						this.formData.isPersonal = this.formData.isPersonal + ''
						console.log(this.formData)
						this.modelIdToCoupon = res.data.modelIdToCoupon
						this.getMyAvailableCoupon(this.modelIdToCoupon)
						if (this.details.couponNo && this.details.couponNo != undefined && this.details.couponNo !=
							null && this.details.couponNo != '') {
							// this.showPreferential = true
							this.getAmount(this.details.couponNo)
						}

					}
				})
			},

			copy(orderId) {
				uni.setClipboardData({
					data: orderId
				})
			},
			cancelOrder() {
				let _this = this
				this.show = true
				uni.showModal({
					title: this.title,
					content: this.dialogContent,
					confirmColor: '#EA5404',
					success: function(res) {
						if (res.confirm) {
							let url = app.globalData.config.interfaces.URL_LIFAN_CANCEL_ORDER
							let params = {
								"id": _this.id
							};
							network.get(url, params, 'form').then(res => {
								if (res.code == 200) {
									uni.showToast({
										title: '取消成功',
										duration: 2000
									})
									_this.getDetail()
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			// refundProgress() {
			// 	uni.navigateTo({
			// 		url: `/module_my/pages/orderList/refundProgress/refundProgress?currentPayType${this.details.currentPayType}&money=${this.details.currentPayType == 1 ? this.details.depositAmount: this.details.finalPayment}`
			// 	});
			// },
			toPay() {
				uni.redirectTo({
					url: `/module_my/pages/orderList/payment/payment?id=${this.id}&currentPayType=${this.details.currentPayType}&money=${this.details.currentPayType == 1 ? this.details.depositAmount: this.showPreferential==false?this.details.finalPayment:(Number(this.carConfig.afterDiscountOrderAmount) * 100 - Number(this.details.depositAmount)* 100) / 100}`
				})
			},
			dialogConfirm(data) {
				this.show = false
			},
			dialogCancel(data) {
				this.show = false
			},


			//获取省
			async getProvinces() {
				var url = app.globalData.config.interfaces.URL_GET_PROVINCE
				var params = {
					// "loginId": app.getUserId()
				}
				await network.get(url, params, 'form').then(res => {
					if (res.code == 200) {
						let arr = []
						res.data.ProvinceList.map(item => {
							item.label = item.provinceName, item.code = item.provinceCode, arr.push(
								item)
						})
						this.cityColumns.splice(0, 1, arr)
						this.getCitys(this.cityColumns[0][0]['provinceCode'])
						consol.log('cityColumns', this.cityColumns)
					} else {
						uni.showToast({
							title: res.message,
							duration: 2000,
							icon: 'none'
						})
					}
				}).catch(res => {

				});
			},
			//获取市
			async getCitys(code) {
				var url = app.globalData.config.interfaces.URL_GET_CITY_BY_PROVINCE
				var params = {
					// "loginId": app.getUserId(),
					"provinceCode": code
				}
				await network.get(url, params, 'form').then(res => {
					if (res.code == 200) {
						let arr = []
						res.data.cityList.map(item => {
							item.label = item.cityName, item.code = item.cityCode, arr.push(item)
						})
						this.cityColumns.splice(1, 1, arr)
						console.log('this.cityColumns', this.cityColumns)
					} else {
						uni.showToast({
							title: res.message,
							duration: 2000,
							icon: 'none'
						})
					}
				}).catch(res => {

				});
			},
			getStoreList(city, notFirst) {
				if (!city) return
				let url = app.globalData.config.interfaces.URL_GETSTORELISTBYCITY
				let params = {
					isCity: city
				}
				network.get(url, params, 'form').then(res => {
					let arr = []
					// res.data.map(item => {item.label = item.storeName, item.code = item.uuid, arr.push(item) })
					this.storeColumns = [res.data]
					console.log('this.storeColumns', this.storeColumns)
					if (!this.storeColumns[0].length && notFirst) {
						uni.showToast({
							title: '当前城市暂无门店',
							duration: 2000,
							icon: 'none'
						})
					}
				})
			},

			/* 门店 */
			cancel(e) {
				this.showCity = false
				this.showStore = false
			},
			cityConfirm(e) {
				console.log('confirm', e)
				this.formData.province = e.value[0].code
				this.formData.city = e.value[1].code
				this.formData.cityName = e.value[1].cityName
				this.getStoreList(e.value[1].code, true)
				this.cancel()
			},
			storeConfirm(e) {
				console.log('confirm', e)
				this.formData.storeId = e.value[0].uuid
				this.formData.storeName = e.value[0].storeName
				this.cancel()
			},

			changeCityHandler(e) {
				console.log('changeCityHandler', e)
				const {
					columnIndex,
					index,
					// 微信小程序无法将picker实例传出来，只能通过ref操作
					picker = this.$refs.uPicker
				} = e
				if (columnIndex === 0) {
					this.getCitys(this.cityColumns[0][index]['provinceCode'])
				}
			},
			changeStoreHandler() {},

			submit() {
				this.$refs.uForm.validate().then(res => {
					// uni.$u.toast('校验通过')
					if (!this.formData.storeId && this.storeColumns[0].length) {
						uni.$u.toast('请选择门店')
						return
					}
					if (this.showPreferential==true&&Number(Number(this.carConfig.afterDiscountOrderAmount || 0) * 10000 - Number(this.details
							.depositAmount || 0) * 10000) / 10000 <= 0) {
						uni.$u.toast('尾款异常')
						return
					}
					this.showConfirm = true
					console.log('formData', this.formData)
					// 

				}).catch(errors => {
					// uni.$u.toast('校验失败')
				})
			},

			confirm(formData) {
				console.log(this.formData.paymentType + "张大硕")
				let url = app.globalData.config.interfaces.URL_LIFAN_UPDATE_ORDER
				let params = {
					...this.formData,
					id: this.id,
					userId: app.getUserId()
				};
				params.deliveryType = parseInt(params.deliveryType)
				params.invoiceType = parseInt(params.invoiceType)
				params.isPersonal = parseInt(params.isPersonal)

				network.post(url, params, 'json').then(res => {
					if (res.code == 200) {
						this.cancle()
						this.toPay()
					} else {
						uni.$u.toast(res.message)
					}
				})
			},

			cancle() {
				this.showConfirm = false
			},

			closePop() {
				this.popupShow = false
			},


		},
	}
</script>

<style lang='scss' scoped>
	@import "./orderDetail.css";

	.order-confirm {
		padding: 0 24px 85px;
		box-sizing: border-box;

		.content {
			padding: 0;

			.price-detail {
				.p-list {
					.right {
						font-weight: 400;
					}

					.money-color {
						display: inline-block;
						// font-weight: 600;
					}
				}

				.total {
					.right {
						font-weight: 600;
						color: #EA5404;
					}
				}

				.weight {
					font-weight: 600;
				}
			}
		}

		.form-title {
			font-weight: 600;
			font-size: 28rpx;
			line-height: 56rpx;
			padding-bottom: 16rpx;
			margin-top: 40rpx;
			border-bottom: 1px solid #EDEDED;
		}

		.tips {
			font-size: 12px;
			line-height: 17px;
			color: #EA5404;
		}

		.form-list {
			display: flex;
			height: 84rpx;
			align-items: center;
			justify-content: space-between;
			font-size: 28rpx;
			line-height: 40rpx;
			color: #3D3A3A;

			.right {
				font-weight: 600;
				color: #EA5404;

				.color {
					display: inline-block;
					color: #3D3A3A;
					margin-right: 10rpx;
				}
			}
		}

		.agreement {
			font-size: 24rpx;
			line-height: 34rpx;
			color: #EA5404;
			margin-top: 20rpx;
			text-align: center;
		}
	}

	.order-detail .o-footer {
		height: 148rpx;
		padding-bottom: 20px;
	}

	.order-detail .o-footer .f-btn {
		width: 100%;
		height: 84rpx;
		line-height: 84rpx;
	}

	/deep/.u-form-item__body__left__content__label {
		color: #ADB0AE;
		font-size: 14px;
	}

	/deep/.uni-textarea-textarea {
		text-align: right;
	}

	/deep/.u-radio-group--row {
		justify-content: flex-end;
	}

	/deep/.u-radio__icon-wrap {
		margin-left: 20rpx;
	}

	/deep/.u-radio__text {
		font-size: 14px !important;
	}

	// /deep/.uni-input-input:disabled {
	// 	background: rgba(0,0,0,0) !important;
	// }
	/deep/.u-icon--right {
		transform: rotate(90deg);
	}

	/deep/.u-radio__icon-wrap .u-icon--right {
		transform: rotate(0deg);
	}

	.space:before {
		content: " ";
		white-space: pre;

	}

	/deep/.u-radio-group--column {
		align-items: flex-end;
	}

	.last-radip {
		position: relative;
		top: 10px;
		/* left:-27px */
	}

	.lala /deep/.u-form-item__body {
		margin-top: 3px;
		align-items: flex-start;
	}

	.orangeText {
		font-weight: 400;
		font-size: 28rpx;
		line-height: 40rpx;
		display: flex;
		align-items: center;
		text-align: right;
		color: #EA5404;
	}
</style>
